
using System;
using System.Collections.Generic;

namespace cachier
{


	public class Machine
	{
		Display display;
		public Machine ()
		{
			display = new Display ();
			
		}

		public void Run ()
		{
			display.setMachine (this);
			display.open ();
		}

		public void HandleCommand (string command)
		{
			Command commandInstance = CommandFactory.ParseCommand (command);
			Display.Out (commandInstance.Process () ? "OK" : "ERROR");
			//DisplayOutput();
		}

		private void DisplayOutput ()
		{
			Dictionary<int, int> data = Storage.GetCurrencyOutput ();
			if (data.Count > 0) {
				foreach (KeyValuePair<int, int> pair in data) {
					Display.Out (pair.Key + " " + pair.Value + " OK");
				}
				Storage.GetCurrencyOutput ().Clear ();
			}
		}
	}
}